package the.broccoli.setting.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wisteria.framework.web.mvc.service.AbstractSuperService;
import the.broccoli.setting.entity.Log;
import the.broccoli.setting.mapper.LogMapper;
import the.broccoli.setting.service.ILogService;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lei.liu
 * @since 2019-11-27
 */
@Service
public class LogServiceImpl extends AbstractSuperService<LogMapper, Log> implements ILogService {

    @Transactional
    @Override
    public void loginLog(String account, String ip) {
        Log log = new Log();
        log.setLogType("用户登录");
        log.setOperatorId(account);
        log.setOperateTime(LocalDateTime.now());
        log.setIp(ip);
        this.baseMapper.insert(log);
    }

    @Override
    public void loginFailLog(String account, String ip, String failMessage) {
        Log log = new Log();
        log.setLogType("用户登录失败");
        log.setOperatorId(account);
        log.setOperateTime(LocalDateTime.now());
        log.setContent(failMessage);
        log.setIp(ip);
        this.baseMapper.insert(log);
    }

    @Override
    public void logoutLog(String account, String ip) {
        Log log = new Log();
        log.setLogType("用户登出");
        log.setOperatorId(account);
        log.setOperateTime(LocalDateTime.now());
        log.setIp(ip);
        this.baseMapper.insert(log);
    }

    @Override
    public void businessLog(String logName, String operatorId, String ip, String content) {

    }
}
